package old.gui;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;


import com.jme3.app.Application;
import com.jme3.asset.AssetManager;
import com.jme3.collision.CollisionResult;
import com.jme3.collision.CollisionResults;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.scene.Geometry;
import com.jme3.system.AppSettings;
import com.jme3.texture.Texture;

import events.ECodeEventList;
import gameAppLayer.MainApp;

//The game's main menu
public class StateMainMenu extends GUILayout
{
	private static final Logger logger = Logger.getLogger(Application.class.getName());
	
	//All GUI elements contained in this GUIState
	public Button button1;
	public Button button2;
	
	public StateMainMenu(MainApp app) {
		super(app, "MAIN_MENU");
		initialize();		
	}
	
	private void initEvents()
	{
		events.add("GUIEVENT_NEW_GAME");
		events.add("GUIEVENT_OPTIONS_MENU");
		//etc.
	}

	@Override
	public void initialize() {		
		//Detach any existing nodes
		this.detachAllChildren();
		
		//Acquire current aspect ratio
		//(DONE)
				
		//Create and attach nodes, geometries, GUIComponent objects at default resolution

		//First component
		//-----------------------------------
		button1 = new Button(100,100);
		
		Geometry geom1 = new Geometry("NEW_GAME", button1);
		geom1.setLocalTranslation(256, 128, 0);
		
		Material mat1 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/SimpleTextured.j3md");
		Texture tex1 = app.getAssetManager().loadTexture("assets/interface/NewGameButton.jpg");
		if (tex1 == null)
		{
			System.out.println("NULL TEXTURE!");
		}
		mat1.setTexture("m_NewGame", tex1);
		//mat1.setTexture("m_NewGame", app.getAssetManager().loadTexture("workspace/Astral Clade/assets/interface/NewGameButton.bmp"));
		//Material mat1 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/SolidColor.j3md");
		//mat1.setColor("m_Color", ColorRGBA.Blue);
    	geom1.setMaterial(mat1);		
		
    	this.attachChild(geom1);
		
    	componentMap.put(button1, geom1);
		//-----------------------------------
				
		//Next component
		//-----------------------------------
		
		//-----------------------------------
				
		//Load all events
		initEvents();		
	}
	
	public void registerListeners()
	{
		app.getInputManager().addListener(this, "LEFT_CLICK");
		//etc.
	}
	
	public void removeListeners()
	{
		app.getInputManager().removeListener(this);		
	}
	
	public void registerEvents()
	{
		for (String event: events)
		{app.getEventManager().addListener(app.getGUIStateManager(), event);}		
	}
	
	public void removeEvents()
	{
		for (String event: events)
		{app.getEventManager().delListener(app.getGUIStateManager(), event);}
	}
		
	//Handle all input actions
	public void onAction(String name, boolean isPressed, float tpf){				
		//Handle messages depending on which element has been acted on
		if (currComponent.equals(button1)){
			
			//define actions based on input types
			if (name.equals("LEFT_CLICK"))
				app.getEventManager().queueEvent(new GUIEvent("GUIEVENT_NEW_GAME", System.currentTimeMillis()));
			
			
		}//http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_picking
		
	}
	
	
	
}

	
	

